/*
 * @lc app=leetcode.cn id=1652 lang=cpp
 *
 * [1652] 拆炸弹
 */

// @lc code=start
class Solution
{
public:
  vector<int> decrypt(vector<int>& code, int k)
  {
    if (k == 0) {
      fill(code.begin(), code.end(), 0);
      return code;
    }
    else {
      int len = abs(k);
      int n = code.size(), step = k > 0 ? 1 : -1;
      vector<int> ans(n);
      for (int i = 0; i < n; ++i) {
        int cnt = 0;
        for (int j = i + step; cnt < len; j += step, ++cnt)
          ans[i] += code[(n + j) % n];
      }
      return ans;
    }
  }
};
// @lc code=end
